package com.site.user.controller;

import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.site.user.pojo.TbRegion;
import com.site.user.pojo.TbUser;
import com.site.user.service.ITbRegionService;


@Controller
@RequestMapping("/region")
public class TbRegionController extends BaseController{
	@Resource
	private ITbRegionService tbRegionService;

	/**
	 * 查询数据列表
	 * @param request
	 * @param response
	 * @param out
	 */
	@RequestMapping(value = "/ser_getRegions", method = RequestMethod.POST)
	public void getRegions(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Content-Type", "text/html;charset=utf-8");
		String id = ServletRequestUtils.getStringParameter(request, "id", "0");
		List cglist = tbRegionService.getRegions(id);

		JSONArray ary=new JSONArray(cglist);
		
		out.println(ary.toString());
	}
	/**
	 * 载入数据
	 * @param request
	 * @param response
	 * @param out
	 */
	
	@RequestMapping(value = "/ser_load", method = RequestMethod.GET)
	public void load(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Content-Type", "text/html;charset=utf-8");

		String id = ServletRequestUtils.getStringParameter(request, "id", "");
		TbRegion obj = null;
		
		if(StringUtils.isNotEmpty(id)){

		obj = tbRegionService.execFindById(id);
		if (obj != null) {
			JSONObject jobj = new JSONObject(obj);
			out.println(jobj.toString());
		}
		}else{
			out.println("");
		}
		
	}
}
